<?php

namespace App\Service\Activity;

use App\Helpers\AliyunUtil;
use App\Model\Act\UserRankAct;
use App\Model\UserProfile;
use App\Service\BaseService;

/**
 * 声优贤惠榜单
 */
class HostRewardRankService extends BaseService
{
    public function handle()
    {
        $ret['list'] = [];
        $rankWeek = $this->request->input('rank_week', 1);
        $rankList = UserRankAct::getList($rankWeek, UserRankAct::ACT_HOST_RANK);
        $ret['userIds'] = $userIds = array_column($rankList, 'user_id');
        $userProfiles = UserProfile::getUsersProfile($userIds, true);
        foreach ($rankList as $rankItem) {
            $userId = $rankItem['user_id'];
            $ret['list'][] = [
                'user_id' => $userId,
                'nick_name' => $userProfiles[$userId]['nick_name'],
                'avatar' => AliyunUtil::IMG_HOST . $userProfiles[$userId]['avatar'],
                'rank_value' => $rankItem['rank_value'] . "分",
                'rank' => $rankItem['rank'],
            ];
        }
        return $ret;
    }
}
